package com.ark.cloud.dataservices.common.exception;

import com.ark.cloud.dataservices.common.web.entity.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandlerAdvice extends DefaultGlobalExceptionHandlerAdvice {

    @ExceptionHandler(value = {UserNotFoundException.class})
    public Result userNotFound(UserNotFoundException ex) {
        log.error(ex.getMessage());
        ex.printStackTrace();
        return Result.fail(ex.getErrorType());
    }

    @ExceptionHandler(value = {UserNameExistException.class})
    public Result userNameExist(UserNameExistException ex) {
        log.error(ex.getMessage());
        ex.printStackTrace();
        return Result.fail(ex.getErrorType());
    }

    @ExceptionHandler(value = {MobileExistException.class})
    public Result mobileExist(MobileExistException ex) {
        log.error(ex.getMessage());
        ex.printStackTrace();
        return Result.fail(ex.getErrorType());
    }
}